<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h2>组件的v-model</h2>
    <p>value: {{ value }}</p>
    <son :value="value" @get-value="getValue"></son>
  </div>

  <script src="../vue3.js"></script>
  <script>

    const {createApp} = Vue;

    const Son = {
      props: {
        value: String
      },
      template: `
        <div>
          <div>这是子组件</div>
          <input type="text" :value="value" @input="$emit('get-value', $event.target.value)" />
        </div>
      `,
    }

    const app = createApp({
      components: {
        Son
      },
      data() {
        return {
          value: "abc"
        }
      },
      methods: {
        getValue(v) {
          this.value = v;
        }
      }
    });

    app.mount("#app");
  </script>
</body>
</html>